<!doctype html>
<html lang="zh-Hans-CN">

	<head>
		<title></title>
		<meta charset="utf-8">
		<meta name="keywords" content="">
		<meta name="description" content="">
		<meta name="author" content="chen">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<meta http-equiv="X-UA-Compatible" content="ie=edge, chrome=1">
		<!--<link rel="stylesheet" type="css/text" media="screen and ( min-width: 1200px )" href="">-->
		<link rel="stylesheet" type="text/css" media="screen" href="">
		<script defer="defer" src=""></script>
		<style>
			/*@import url("css/name.css") screen and ( min-width: 1200px );*/
		</style>
	</head>
	
	<body>
		<button id='btn'>下载指定格式文件</button>
		<script>
			let btn = document.getElementById('btn');
			// 写入文本内容
			let str = encodeURI('今天是周末, 大家都想吃鸡');
			// 调用下载文件函数直接下载一个指定格式文件, 参数分别为 文件名, 文件内容, 文件类型
			downloadFile('dream.doc', str, 'application.msword');
			function downloadFile( fileName, fileContent, fileType ) {
				// 创建Blob对象指向文件内容
				let blob = new Blob([decodeURI(fileContent)], {fileType});
				// 创建blob的URL
				let url = window.URL.createObjectURL(blob);
				// 创建<a>元素
				let link = document.createElement('a');
				link.href = url;
				link.download = '指定类型的文件.doc';
				link.click();
			}
		</script>
	</body>

</html>